package com.example.administrator.baikangxing.activity;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import com.example.administrator.baikangxing.R;

public class FeedBackActivity extends BaseActivity {

    private EditText feed_back_et_content;
    private TextView feed_back_tv_count;
    private int num = 800;

    @Override
    public int getContentViewLayoutId() {
        return R.layout.activity_feed_back;
    }

    @Override
    public void initView() {
        setTitles("意见反馈");
        feed_back_tv_count = findView(R.id.feed_back_tv_count);
        feed_back_et_content = findView(R.id.feed_back_et_content);
        feed_back_et_content.requestFocus();
    }

    @Override
    public void initListener() {
        feed_back_et_content.addTextChangedListener(new TextWatcher() {
            private CharSequence temp;
            private int selectionStart;
            private int selectionEnd;
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                temp = charSequence;
            }

            @Override
            public void afterTextChanged(Editable editable) {
                feed_back_tv_count.setText(editable.length()+"/"+num+"字");
                selectionStart = feed_back_et_content.getSelectionStart();
                selectionEnd = feed_back_et_content.getSelectionEnd();
                if (temp.length() > num) {
                    editable.delete(selectionStart - 1, selectionEnd);
                    int tempSelection = selectionStart;
                    feed_back_et_content.setText(editable);
                    feed_back_et_content.setSelection(tempSelection);//设置光标在最后
                }
            }
        });
    }

    @Override
    public void initData() {

    }
}
